{% extends 'base.html' %}

{% block title %}首页{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h1 class="mb-4">产品组价管理系统</h1>
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">最新产品列表</h5>
            </div>
            <div class="card-body">
                {% if products %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>类别</th>
                                <th>规格</th>
                                <th>材料成本</th>
                                <th>人工成本</th>
                                <th>总价</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for product in products %}
                            <tr>
                                <td>{{ product.id }}</td>
                                <td>{{ product.name }}</td>
                                <td>{{ product.category }}</td>
                                <td>{{ product.specification }}</td>
                                <td>{{ "%.2f"|format(product.material_cost) }}</td>
                                <td>{{ "%.2f"|format(product.labor_cost) }}</td>
                                <td>{{ "%.2f"|format(product.total_price) }}</td>
                                <td>
                                    <a href="{{ url_for('product_detail', product_id=product.id) }}" class="btn btn-sm btn-primary">详情</a>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <p class="text-muted">暂无产品数据</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}